
package csse3004.GD.PAdmin;

/**
 * @author Mamdouh Alharbi 4194298
 */
import org.springframework.validation.Validator;
import org.springframework.validation.Errors;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ChangePasswordValidator implements Validator{
    
    protected final Log logger = LogFactory.getLog(getClass());

    public boolean supports(Class clazz) {
        return ChangePassword.class.equals(clazz);
    }
    
    public void validate(Object obj, Errors errors) {
        
        ChangePassword changePassword = (ChangePassword) obj;
        String oldPassword = changePassword.getOldPassword();
        String newPassword = changePassword.getNewPassword();
      
        logger.info("Checking Empty String for the poll name in the pollName page");
        logger.info("in the validator");
        
        if (oldPassword == "") {
            errors.rejectValue("oldPassword", "error.not-specified", null, "Old Password is Required.");
        }
        if (newPassword == ""){
            errors.rejectValue("newPassword", "error.not-specified", null, "New Password is Required.");
        }
    }
    
    
}
